from lxml import etree
import requests

headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36'
}
# url = 'https://smx.58.com/ershoufang/?PGTID=0d100000-0246-5183-e9ab-fd226b1e9aa8&ClickID=2'
page_text = requests.get(url,headers).text
print(page_text)
tree = etree.HTML(page_text)
li_list = tree.xpath('//ul[@class="house-list-wrap"]/li')
# print(li_list)
with open('./house.txt','a',encoding='utf-8') as f:
    for each in li_list:
        house = each.xpath('./div[2]/h2/a/text()')[0]
        pirce = each.xpath('./div[3]/p/b/text()')[0]
        ares = each.xpath('./div[2]/p/span[2]/text()')[0]
        print(pirce,house)
        f.write(house + ares + pirce + '万' +'\n')